package com.two.user.service.impl;

import java.util.List;

import com.two.user.dao.UserDao;
import com.two.user.dao.impl.UserDaoImpl;
import com.two.user.model.User;
import com.two.user.service.UserService;

public class UserServiceImpl implements UserService{
	/**login服务层实现*/
	@Override
	public boolean login(String username, String password) {
		UserDao dao = new UserDaoImpl();			//获取持久层对象
		User user = dao.selectByname(username);		//调用方法来查询用户对象
		//验证账号和密码
		if(user != null && user.getUsername().equals(username) 
				&& user.getPassword().equals(password)) {
			return true;
		}
		return false;
	}

	/**查询所有用户服务层实现*/
	public List<User> selectAll() {
		UserDao dao = new UserDaoImpl();
		return  dao.selectAll();
	}

	/**添加用户服务层实现*/
	@Override
	public boolean addUser(String username, String password, String age, String gender, String remake) {
		UserDao dao = new UserDaoImpl();
		int a = Integer.valueOf(age);
		int n = dao.addUser(username, password, a, gender, remake);
		return n>0;
	}
	
	
	/**根据id查询用户*/
	@Override
	public User selectById(String id) {
		UserDao dao = new UserDaoImpl();
		int no = Integer.valueOf(id);
		return dao.selectById(no);
	}
	
	
	/**更新用户服务层实现*/
	@Override
	public boolean updateUser(String id, String username, String password, String age, String gender, String remark) {
		UserDao dao = new UserDaoImpl();
		int a = Integer.valueOf(age);
		int i = Integer.valueOf(id);
		int n = dao.updateUser(i, username, password, a, gender, remark);
		return n>0;
	}
	
	
	/**删除服务层实现*/
	@Override
	public boolean deleteUser(String id) {
		UserDao dao = new UserDaoImpl();
		int i = Integer.valueOf(id);
		int n = dao.deleteUser(i);
		return n>0;
	}

	
	
}
